<template>
  <div class="contain">
    <div class="author">
      <div class="authortipes">作者名称</div>
      <div class="names">{{dataForm.name}}</div>
      <div class="authortipes">作者简介</div>
      <div class="introLs">{{dataForm.introL}}</div>
    </div>
  </div>
</template>

<script>
import { navto } from "@/utils/util";
import { toast } from "@/utils/index";
import { getPoemsAuthorById, getPoetryAuthorById } from "@/api/api";
export default {
  data() {
    return {
      id: 0, //作者id
      st: 1,
      dataForm: {
        name: "",
        introL: ""
      } //数据存储地方
    };
  },
  onLoad(e) {
    this.id = 0;
    console.log(e);
    this.id = e.author;
    this.st = e.st;
  },
  onShow() {
    let token = mpvue.getStorageSync("token") || "";
    if (token) {
      this.dataForm = {
        name: "",
        introL: ""
      };
      this.getAuthor();
    } else {
      this.getToken();
    }
  },

  methods: {
    getToken() {
      // 跳转回授权页面
      navto("/pages/authorization/main", "");
    },
    /**
     * 根据作者id查生平
     */
    getAuthor() {
      let id = this.id;
      if (this.st == 1) {
        getPoemsAuthorById({ id: id }).then(res => {
          this.detailData(res);
        });
      } else if (this.st == 2) {
        getPoetryAuthorById({ id: id }).then(res => {
          this.poetryDetailData(res);
        });
      }
    },
    /**
     * 处理数据
     */
    detailData(res) {
      console.log(res);
      if (res.data) {
        this.dataForm.name = res.data.name;
        this.dataForm.introL = res.data.introL.length
          ? res.data.introL.replace(/(^\s*)|(\s*$)/g, "")
          : "";
      }
    },
    poetryDetailData(res) {
      console.log(res);
      if (res.data) {
        this.dataForm.name = res.data.name;
        this.dataForm.introL = res.data.intro.length
          ? res.data.intro.replace(/(^\s*)|(\s*$)/g, "")
          : "";
      }
    }
  }
};
</script>

<style lang='less' scope>
.contain {
  width: 90%;
  margin: 0rpx auto;
  margin-top: 25rpx;
  box-sizing: border-box;
  background-color: #fff;
  .author {
    font-size: 28rpx;
    margin: 22rpx auto;
    .authortipes {
      font-size: 32rpx;
      font-weight: 600;
      display: flex;
      padding-left: 22rpx;
      border-left: 8rpx solid rgb(173, 46, 46);
      color: rgb(173, 46, 46);
    }
    .names {
      margin: 25rpx 0;
      padding-left: 35rpx;
      font-size: 32rpx;
    }
    .introLs {
      margin-top: 25rpx;
      margin-bottom: 45rpx;
      padding-left: 35rpx;
      font-size: 28rpx;
      text-indent: 50rpx;
    }
  }
}
</style>
